2da56feded0f8030df79249f80b702bb39b44488,subprojects/testing-jvm/src/main/java/org/gradle/api/internal/tasks/testing/testng/TestNGTestClassProcessor.java,TestNGTestClassProcessor,runTests,#,86
Before Change
testNg.setThreadCount(options.getThreadCount());
String configFailurePolicy = options.getConfigFailurePolicy();
try {
JavaReflectionUtil.method(TestNG.class, Object.class, "setConfigFailurePolicy", String.class).invoke(testNg, configFailurePolicy);
} catch (NoSuchMethodException e) {
if (!configFailurePolicy.equals(TestNGOptions.DEFAULT_CONFIG_FAILURE_POLICY)) {
// Should not reach this point as this is validated in the test framework implementation - just propagate the failure
throw e;
}
}
try {
JavaReflectionUtil.method(TestNG.class, Object.class, "setAnnotations").invoke(testNg, options.getAnnotations());
} catch (NoSuchMethodException e) {
/* do nothing; method has been removed in TestNG 6.3 */
}
if (options.getJavadocAnnotations()) {
testNg.setSourcePath(CollectionUtils.join(File.pathSeparator, options.getTestResources()));
}
testNg.setUseDefaultListeners(options.getUseDefaultListeners());
testNg.setVerbose(0);
testNg.setGroups(CollectionUtils.join(",", options.getIncludeGroups()));
testNg.setExcludedGroups(CollectionUtils.join(",", options.getExcludeGroups()));
//adding custom test listeners before Gradle's listeners.
//this way, custom listeners are more powerful and, for example, they can change test status.
for (String listenerClass : options.getListeners()) {
try {
testNg.addListener(applicationClassLoader.loadClass(listenerClass).newInstance());
} catch (Throwable e) {
throw new GradleException(String.format("Could not add a test listener with class '%s'.", listenerClass), e);
}
}
if (!options.getIncludedTests().isEmpty()) {
testNg.addListener(new SelectedTestsFilter(options.getIncludedTests()));
}
if (!suiteFiles.isEmpty()) {
testNg.setTestSuites(GFileUtils.toPaths(suiteFiles));
} else {
testNg.setTestClasses(testClasses.toArray(new Class[testClasses.size()]));
}
testNg.addListener((Object) adaptListener(new TestNGTestResultProcessorAdapter(resultProcessor, idGenerator, timeProvider)));
try {
JavaReflectionUtil.method(TestNG.class, void.class, "setPreserveOrder", boolean.class).invoke(testNg, options.getPreserveOrder());
} catch (NoSuchMethodException e) {
if (options.getPreserveOrder()) {
throw new GradleException("Preserving the order of tests is not supported by this version of TestNG.", e);
}
}
try {
JavaReflectionUtil.method(TestNG.class, void.class, "setGroupByInstances", boolean.class).invoke(testNg, options.getGroupByInstances());
} catch (NoSuchMethodException e) {
if (options.getGroupByInstances()) {
throw new GradleException("Grouping tests by instances is not supported by this version of TestNG.", e);
After Change
}
private void runTests() {
TestNG testNg = new TestNG();
testNg.setOutputDirectory(testReportDir.getAbsolutePath());
testNg.setDefaultSuiteName(options.getDefaultSuiteName());
testNg.setDefaultTestName(options.getDefaultTestName());
testNg.setParallel(options.getParallel());
testNg.setThreadCount(options.getThreadCount());
invokeVerifiedMethod(testNg, "setConfigFailurePolicy", String.class, options.getConfigFailurePolicy(), TestNGOptions.DEFAULT_CONFIG_FAILURE_POLICY);
invokeVerifiedMethod(testNg, "setPreserveOrder", boolean.class, options.getPreserveOrder(), false);
invokeVerifiedMethod(testNg, "setGroupByInstances", boolean.class, options.getGroupByInstances(), false);
try {
JavaReflectionUtil.method(TestNG.class, Object.class, "setAnnotations").invoke(testNg, options.getAnnotations());
} catch (NoSuchMethodException e) {